package com.ipc.app.web.ajax;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.ipc.app.biz.UserBiz;
import com.ipc.app.model.User;

@Controller
@RequestMapping(value = "/jsp/registrationAjax.do")
public class RegistrationAjax {

	@Autowired
	private UserBiz userBiz;

	@RequestMapping(method = RequestMethod.GET)
	public void registrationValidation(ModelMap model, String mobile,
			HttpServletResponse response) {
		User user = userBiz.getUserByMobile(mobile);
		response.setContentType("text/html");

		PrintWriter writer = null;
		try {
			writer = response.getWriter();
			String userExist = "T";
			if (null == user) {
				userExist = "F";
			}
			writer.write(userExist);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			if (null != writer) {
				writer.flush();
				writer.close();
			}
		}

	}
}
